package com.vipheyue.lanjingapp.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bmob.BmobProFile;
import com.bmob.btp.callback.ThumbnailListener;
import com.lidroid.xutils.util.LogUtils;
import com.vipheyue.lanjingapp.R;
import com.vipheyue.lanjingapp.bean.Company;
import com.vipheyue.lanjingapp.bean.Job;
import com.vipheyue.lanjingapp.utils.GsonUtils;
import com.vipheyue.lanjingapp.utils.ImageUtil;
import com.vipheyue.lanjingapp.utils.StatusBarCompat;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class CompanyDetailActivity extends Activity {

    @Bind(R.id.iv_company)
    ImageView iv_company;
    @Bind(R.id.tv_company_name)
    TextView tv_company_name;
    @Bind(R.id.tv_companyDescription)
    TextView tv_companyDescription;
    @Bind(R.id.rl_menu_left)
    RelativeLayout rl_menu_left;
    @Bind(R.id.tv_Menu_Title)
    TextView tv_Menu_Title;
    @Bind(R.id.iv_menu_right)
    ImageView iv_menu_right;
    @Bind(R.id.rl_menu_right)
    RelativeLayout rl_menu_right;
    private String jobStr;
    private Company company;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_company_detail);
        ButterKnife.bind(this);
        StatusBarCompat.compat(this, 0xFF00ABEC);
        initData();
//        createSmartImg();
    }

    private void initData() {
        tv_Menu_Title.setText("公司详情");
        Intent intent = this.getIntent();
        jobStr = intent.getStringExtra("jobStr");
        LogUtils.i("jobStr" + jobStr);
        Job job = GsonUtils.fromJson(jobStr, Job.class);
        company = job.getPublisherCompany();
//        String url = company.getCompanyLogo().getFileUrl(this);
//        String url = BmobProFile.getInstance(this).signURL(company.getCompanyLogo().getFilename(), company.getCompanyLogo().getUrl(), "7fc03f65e66cbe0d58ff13177a0966b5", 100, "MySecretKey");
        String url = BmobProFile.getInstance(this).signURL("b7f4bd7455a84b35be7c491de7829569.jpg_1", "http://newfile.codenow.cn:8080/b7f4bd7455a84b35be7c491de7829569.jpg_1", "7fc03f65e66cbe0d58ff13177a0966b5", 999999999, null);

        LogUtils.i("url----->    " + url);
        ImageUtil.setImageURI(this, iv_company, url);
        tv_company_name.setText(company.getCompanyName());
        tv_companyDescription.setText(company.getCompanyDescription());
    }
    public void createSmartImg(){
        BmobProFile.getInstance(this).submitThumnailTask("b7f4bd7455a84b35be7c491de7829569.jpg", 1, new ThumbnailListener() {

            @Override
            public void onSuccess(String thumbnailName,String thumbnailUrl) {
                // TODO Auto-generated method stub
                //此处得到的缩略图地址（thumbnailUrl）不一定能够请求的到，此方法为异步方法
                Log.i("bmob", "onSuccess :" + thumbnailName + "-->" + thumbnailUrl);
            }

            @Override
            public void onError(int statuscode, String errormsg) {
                // TODO Auto-generated method stub
                Log.i("bmob","onError :"+statuscode+"---"+errormsg);
            }
        });
    }



    @OnClick(R.id.rl_menu_left)
    public void onClick() {
        finish();
    }
}
